package com.navinfo.platform.bigdata.hive.udf;

import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.IntWritable;

public class DiffByWeightUDF extends UDF {

    /**
     * 获取num第index位的bit值
     * @param total
     * @param other
     * @return
     */
    public IntWritable evaluate(IntWritable total, IntWritable curValue, IntWritable ... other) {
        int sum = curValue.get();
        int otherSum = 0;
        for(IntWritable data : other){
            sum += data.get();
            otherSum += data.get();
        }
        int admendData = (int) Math.round(total.get() * (1 - otherSum * 1.0/sum));
        return new IntWritable(admendData);
    }
}
